class Mates:
    def __init__(self):
        self.friends = list()
    
    def add(self, name):
        self.friends.append(name)

    def __iter__(self):
        # 一个类 如果实现了 __iter__() 就是可迭代对象
        # __iter__() 方法 必须返回一个迭代器的引用
        # 迭代器就是一个实现了__iter__()和__next__()的类
        return MatesIterator(self)

class MatesIterator:
    def __init__(self, obj):
        self.obj = obj
        self.current = 0
        
    def __iter__(self):
        pass
    def __next__(self):
        if self.current < len(self.obj.friends):
            ret = self.obj.friends[self.current]
            self.current += 1
            return ret
        else:
            raise StopIteration

mates = Mates()
mates.add("赵")
mates.add("钱")
mates.add("孙")
mates.add("李")

for temp in mates:
    print(temp)
